<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.1.1/jquery.min.js"></script>
    <link href="static/bootstrap-3.4.1-dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="static/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
    <title>登录失败页面</title>
</head>
<body>
<div style="width:50%;height:50%;position:absolute;top:25%;left:35%;">
    <div style="width: 580px;vertical-align: middle;text-align: center;"><h2 >登录失败！</h2></div>
</div>
<div id="errorTips" style="text-align: center;font-size: 18px;color: red"></div>
</body>
</html>
<script>
    $(function() {
        var $name = $('input[name=username]');
        var $password = $('input[name=password]');
        $('#btnSubmit').click(function() {
            if($name.val() != '' && $password.val() != '') {
                //使用 $.ajax-get 发送请求
                Jquery_AJAX_GET_demo();
                //使用 $.ajax-post 发送请求
                //Jquery_AJAX_POST_demo();
            }
        });
        //使用 $.ajax()   方法发送请求
        function Jquery_AJAX_GET_demo() {
            $.ajax({
                type: "get",
                contentType: "application/json",
                url: 'http://localhost:8080/week13_war/login.do',
                dataType: "json",
                data: {
                    username: $('input[name=username]').val(),
                    password: $('input[name=password]').val()
                },
                async: "true",
                success: function (result) {
                    if (result.status == 'error') {
                        $('#errorTips').text("用户名或密码错误!");
                    } else if (result.status == 'success') {
                        window.location.href= "http://localhost:8080/week13_war/login_Result.jsp";
                    }
                },
                error: function (e) {
                    alert("error")
                }
            })
        }
        //使用 $.ajax() 的 post 方法 发送请求
        function Jquery_AJAX_POST_demo() {
            $.ajax({
                type: "post",
                contentType: "application/x-www-form-urlencoded",
                url: 'http://localhost:8080/week13_war/login.do',
                dataType: "json",
                data: $('#myForm').serialize(),
                success: function(result) {
                    if(result.status == 'error') {
                        $('#errorTips').text("用户名或密码错误!");
                    } else if(result.status == 'success') {
                        window.location.href = "http://localhost:8080/week13_war/login_Result.jsp";
                    }
                },
                error: function(e) {
                    alert("error")
                }
            })
        }
    })
</script>